﻿using System;
using System.Collections.Generic;
using System.Text;

namespace RaisingStudio.Data.Common.Factories
{
    /// <summary>
    /// Database transaction manager factory.
    /// </summary>
    public class TransactionManagerFactory
    {
        /// <summary>
        /// Create database transaction manager.
        /// </summary>
        /// <param name="connection">database connection.</param>
        /// <returns>database transaction manager.</returns>
        public static TransactionManager CreateTransactionManager(System.Data.IDbConnection connection)
        {
            return new TransactionManager(connection);
        }

        /// <summary>
        /// Create database transaction manager.
        /// </summary>
        /// <returns>database transaction manager.</returns>
        public static TransactionManager CreateTransactionManager()
        {
            System.Data.IDbConnection connection = ConnectionFactory.CreateConnection();
            return CreateTransactionManager(connection);
        }

        /// <summary>
        /// Create database transaction manager.
        /// </summary>
        /// <param name="connectionName">the name of connection.</param>
        /// <returns>database transaction manager.</returns>
        public static TransactionManager CreateTransactionManager(string connectionName)
        {
            System.Data.IDbConnection connection = ConnectionFactory.CreateConnection(connectionName);
            return CreateTransactionManager(connection);
        }

        /// <summary>
        /// Create database transaction manager.
        /// </summary>
        /// <param name="databaseType">database type.</param>
        /// <param name="connectionString">connection string.</param>
        /// <returns>database transaction manager.</returns>
        public static TransactionManager CreateTransactionManager(DatabaseType databaseType, string connectionString)
        {
            System.Data.IDbConnection connection = ConnectionFactory.CreateConnection(databaseType, connectionString);
            return CreateTransactionManager(connection);
        }

        public static TransactionManager CreateTransactionManager(string providerName, string connectionString)
        {
            System.Data.IDbConnection connection = ConnectionFactory.CreateConnection(providerName, connectionString);
            return CreateTransactionManager(connection);
        }
    }
}
